import Vue from 'vue'

const Consts = {
	clone: function(obj) {
		let newObj = {}
		let propNames = Object.getOwnPropertyNames(obj) //  取回定义在obj上的属性名
		//  在冻结自身之前冻结属性
		propNames.forEach(function(name) {
			newObj[name] = obj[name]
		})
		return newObj
	},
	initPage: function() {
		return JSON.parse(JSON.stringify(this.PAGE_INFO))
	},
	LoginType: {
		Pwd: 0,
		Captcha: 1
	},
	USER_INFO: 'userInfo',
	LOGIN_INFO: 'loginInfo',
	STORE_STATE: 'store_state',
	PageInfo: {
		curPageNum: 0,
		pageSize: 6,
		totalPage: 1
	},
	Bank: {
		Card_0: {
			name: '中国农业银行',
			clazz: 'zgnyyh',
			color: '#08dd6c',
			icon: require('@/static/images/zgnyyh.png')
		},
		Card_1: {
			name: '中国工商银行',
            clazz: 'zggsyh',
			color: '#fc6a6a',
			icon: require('@/static/images/zgnyyh.png')
		},
		Card_2: {
			name: '支付宝',
            clazz: 'zfb',
			color: '#6ca4d9',
			icon: require('@/static/images/zgnyyh.png')
		},
		Card_3: {
			name: '微信',
            clazz: 'wx',
			color: '#00d100',
			icon: require('@/static/images/zgnyyh.png')
		},
	}
}

//  深层冻结对象属性，不允许修改
function deepFreeze(obj) {
	let propNames = Object.getOwnPropertyNames(obj) //  取回定义在obj上的属性名
	//  在冻结自身之前冻结属性
	propNames.forEach(function(name) {
		let prop = obj[name]
		if (typeof prop === 'object' && prop !== null) { //  如果prop是个对象，冻结它
			deepFreeze(prop)
		}
	})
	return Object.freeze(obj) //  冻结自身(no-op if already frozen)
}

deepFreeze(Consts)
Vue.prototype.$Consts = Consts
export {
	Consts
}
